﻿Public Class ReportUT520
    Inherits System.Web.UI.Page

    Private Property DataSource As Data.DataTable
        Get
            Return Me.Session("datasourceut520")
        End Get
        Set(ByVal value As Data.DataTable)
            Me.Session("datasourceut520") = value
        End Set
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearch.Click
        Dim dteFrom As String = Nothing
        Dim dteTo As String = Nothing

        If Not String.IsNullOrEmpty(Me.fromDate.value) Then
            dteFrom = New DateTime(Me.fromDate.Year, Me.fromDate.Month, Me.fromDate.Day).AddYears(-543).ToString("dd/MM/yyyy")
        End If

        If Not String.IsNullOrEmpty(Me.toDate.value) Then
            dteTo = New DateTime(Me.toDate.Year, Me.toDate.Month, Me.toDate.Day).AddYears(-543).ToString("dd/MM/yyyy")
        End If

        DataSource = BL.Report.ReportUT520(dteFrom, dteTo, Me.ucPopupOfficer1.OfficerId)

        Bind(0)
    End Sub

    Private Sub Bind(ByVal pageIndex As Integer)
        Me.gvList.DataSource = DataSource
        Me.gvList.PageIndex = pageIndex
        Me.gvList.DataBind()
    End Sub

    Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnReset.Click
        Me.Session.Remove("datasourceut520")
        Response.Redirect("ReportUT520.aspx", False)
    End Sub

    Private Sub gvList_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvList.PageIndexChanging
        Bind(e.NewPageIndex)
    End Sub

    Protected Sub btnExcel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnExcel.Click
        If Me.DataSource Is Nothing OrElse Me.DataSource.Rows.Count = 0 Then
            Exit Sub
        End If

        Dim dt As DataTable = Me.DataSource
        dt.Columns.Add("OrderNo")
        Dim i As Integer = 0
        For Each dr As DataRow In dt.Rows
            i += 1
            dr("OrderNo") = i.ToString
        Next
        Common.Utility.ExportToSpreadsheet(gvList, dt, "LoginReport")
    End Sub

    Public Shared Function OrderNuber() As String
        Return String.Empty
    End Function

End Class